#ifndef _PHVEC2_H_
#define _PHVEC2_H_

#include <math.h>

class PHVEC2
{
public:

	// Used to allow the data in the vector to be accessed in different ways
	union
	{
		// Access the vector as an array
		float v[2];

		// Access the vector's individual components
		struct
		{
			float x;
			float y;
		};
	};

	// Constructors
	PHVEC2(){ x = y = 0; }

	PHVEC2(float _x, float _y){ x = _x; y = _y; }

	inline PHVEC2 operator+(const PHVEC2 &_phVec2) const
	{
		return PHVEC2(x + _phVec2.x, y + _phVec2.y);
	}

	inline PHVEC2 operator-(const PHVEC2 &_phVec2) const
	{
		return PHVEC2(x - _phVec2.x, y - _phVec2.y);
	}

	inline PHVEC2 operator*(const PHVEC2 &_phVec2) const
	{
		return PHVEC2(x * _phVec2.x, y * _phVec2.y);
	}

	inline PHVEC2 operator/(const PHVEC2 &_phVec2) const
	{
		return PHVEC2(x / _phVec2.x, y / _phVec2.y);
	}

	inline PHVEC2 operator+(float _fV) const
	{
		return PHVEC2(x + _fV, y + _fV);
	}

	inline PHVEC2 operator-(float _fV) const
	{
		return PHVEC2(x - _fV, y - _fV);
	}

	inline PHVEC2 operator/(float _fV) const
	{
		return PHVEC2(x / _fV, y / _fV);
	}

	inline PHVEC2 &operator=(const PHVEC2 &_phVec2)
	{
		x = _phVec2.x;
		y = _phVec2.y;
		return *this;
	}

	inline PHVEC2 &operator+=(const PHVEC2 &_phVec2)
	{
		x += _phVec2.x;
		y += _phVec2.y;
		return *this;
	}

	inline PHVEC2 &operator-=(const PHVEC2 &_phVec2)
	{
		x -= _phVec2.x;
		y -= _phVec2.y;
		return *this;
	}

	inline PHVEC2 &operator*=(float _fV)
	{
		x *= _fV;
		y *= _fV;
		return *this;
	}

	inline PHVEC2 &operator/=(float _fV)
	{
		x /= _fV;
		y /= _fV;
		return *this;
	}

	inline PHVEC2 &MakeZero()
	{
		x = y = 0;
		return *this;
	}

	inline PHVEC2 &Negate()
	{
		x = -x;
		y = -y;
		return *this;
	}

	inline float DotProduct(const PHVEC2 &_phVec2) const
	{
		return x * _phVec2.x + y * _phVec2.y;
	}

	inline friend float DotProduct(const PHVEC2 &_phA, const PHVEC2 &_phB)
	{
		return _phA.DotProduct(_phB);
	}

	inline float Magnitude() const
	{
		return (float)sqrt(DotProduct(*this));
	}

	inline PHVEC2 &Normalize()
	{
		float _phInvMag = 1 / Magnitude();
		*this *= _phInvMag;
		return *this;
	}
};

#endif